//# sourceURL=http://uMapApp/Module/WorkManageModule/WorkManageIntroModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth",
    "../Module"
    , "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/PanelBlock"
    , "../../UI/Panel/PanelBlock/TreeBlock"
    , "./WorkAreaPointModule"
    , "../../UI/Tree/Tree"
], function (
    mhjs,
    uMap,
    uEarth,
    Module
    , FloatPanel
    , PanelBlock
    , TreeBlock
    , WorkAreaPointModule
    , Tree
) {

    function WorkManageIntroModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "工区简介";
        _this.icon = _this.app.icons.home;

        _this.modules = {};

        _this.cargoTile = _this.parentModule.cargoTile;

        _this.modules.workAreaPointModule = new WorkAreaPointModule({
            "app"         : _this.app,
            "parentModule": _this
        });

        _this.leftPanel = new FloatPanel({
            "class"     : "leftPanel newPanel",
            "title"     : "工区简介",
            "showMinMax": true
        });

        _this.infoBlock = new PanelBlock({
            "title"  : "工区概况",
            "content": "　　沿江公司黎里养护工区项目总投资额约340万元，于2020年5月组织实施，2022年10月改造完工后正式投入使用，建筑面积2500平方，占地面积约7500平方。设有各类办公室10间，党建室、QC活动室、数字化系统功能室、打印室、阅览室等功能齐全，布局合理，同时将养护职责、安全网络图、养护组织架构和养护管理体系统一上墙。为统一停放各类养护设备及冬防物资, 公司新建车库800平方，设有10个停车位，5间库房，摆放融雪剂10余吨，锥桶200余个，标志标牌2套等冬防物资。"
        });

        _this.chartBlock = new PanelBlock({
            "title"  : "工区组织架构",
            "content": new mhjs.Img({"src": "./img/systemchart.png"})
        });

        _this.leftPanel
            .append(_this.infoBlock)
            .append(_this.chartBlock)
        ;

        _this.rightPanel = new FloatPanel({
            "class"     : "rightPanel newPanel",
            "showMinMax": true,
            "title"     : "工区管理制度"
        });

        _this.ruleBlock = new TreeBlock({
            "title": "工区管理制度",
            "class": "fullBlock"
        });

        _this.systemBlock = new PanelBlock({
            "title": "工区体系"
        });

        _this.rightPanel
            .append(_this.ruleBlock)
        // .append(_this.systemBlock)
        ;

        _this.app.ui.layout.left.append(_this.leftPanel);
        _this.app.ui.layout.right.append(_this.rightPanel);

        _this.viewport = {
            "center": {
                "longitude": 120.72446589304138, "latitude": 31.045683174766587, "height": 13.164426457514441
            }, "hpr": {
                "heading": 321.7918339863259, "pitch": -32.73276218264122, "range": 376.5827522270923
            }
        };

        _this.getFile("工区管理制度", function (list) {
            _this.renderFiles(_this.ruleBlock.tree, list);
            _this.ruleBlock.tree.openChild();
        });


    }

    var _class = WorkManageIntroModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "open"       : {
            value: function () {
                var _this = this;

                _this.cargoTile.open();

                _this.leftPanel.open();
                _this.rightPanel.open();
                _this.modules.workAreaPointModule.open();
                _this.parentModule.modules.workAreaCameraModule.open();

                _this.app.flyVP(_this.viewport);

                _this.isOpened = true;
                _this.trigger("open");
                _this.trigger("toggle");
            }
        },
        "close"      : {
            value: function () {
                var _this = this;

                _this.cargoTile.close();

                _this.leftPanel.close();
                _this.rightPanel.close();
                _this.modules.workAreaPointModule.close();
                _this.parentModule.modules.workAreaCameraModule.close();

                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "getFile"    : {
            value: function (path, callback) {
                var _this = this;

                _this.app.servers.DC.requests.sc_files.send({"path": path}, function (json) {
                    if (json.data && json.data.list) {
                        callback && callback(json.data.list);
                    }
                });

            }
        },
        "renderFiles": {
            value: function (parentTree, fileList) {
                var _this = this;

                $.each(fileList, function (i, file) {

                    var tree = new Tree({
                        "title": file.fileName
                    });

                    if (file.file) {

                        if (file.url) {
                            tree.url = file.url;
                        }

                    } else {

                        tree.list = [];
                        tree.isChildLoaded = false;

                        tree.ui.titleDiv.on("click", function () {
                            if (!tree.isChildLoaded) {
                                _this.getFile(file.path, function (list) {
                                    _this.renderFiles(tree, list);
                                    tree.openChild();
                                });
                            }
                        });

                    }

                    parentTree.add(tree);


                });


            }
        }
    });

    return _class;

});